package com.nidu.demo.oauth2.ability;

import com.nidu.demo.oauth2.gateway.OAuth2ApproveGateway;
import com.nidu.demo.oauth2.model.OAuth2Approve;
import com.nidu.demo.oauth2.model.OAuth2Client;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
@RequiredArgsConstructor
public class OAuth2ApproveDomainService {

    private final OAuth2ApproveGateway gateway;

    public OAuth2Approve createApprove(Long userId, Integer userType, OAuth2Client client, List<String> scopes) {
        OAuth2Approve approve = OAuth2Approve.create(userId, userType, client.getId(), scopes, LocalDateTime.now().plusSeconds(client.getApproveValiditySeconds()));
        return gateway.create(approve);
    }
}
